package com.yaolin.jfinal.ioc;

import org.osgl.inject.Genie;

import com.jfinal.aop.Enhancer;

/**
 * @author yaolin
 *
 */
public class IocKit {

	private static Genie genie;
	private IocKit() {
	}
	
	/**
	 * 初始化
	 * @param genie
	 */
	static void init(Genie genie) {
		IocKit.genie = genie;
	}
	
	/**
	 * 获取Bean
	 * @param clazz beanType
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getBean(Class<?> clazz) {
		Object bean = genie.get(clazz);
		if (bean == null) {
			return null;
		}
		Aop aop = clazz.getAnnotation(Aop.class);
		if (aop != null) {
			return Enhancer.enhance(bean);
		}
		return (T) bean;
	}
}
